package com.omi.iberolactalpreventa.objects;

import java.util.ArrayList;

import com.omi.iberolactalpreventa.R;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class AdapterItmProducto extends BaseAdapter{

	protected Activity activity;
	protected ArrayList<ItmProducto> items;
	
	
	
	public AdapterItmProducto(Activity activity, ArrayList<ItmProducto> items) {
		this.activity = activity;
		this.items = items;
	}

	@Override
	public int getCount() {
		return items.size();
	}

	@Override
	public Object getItem(int position) {
		return items.get(position);
	}

	@Override
	public long getItemId(int position) {
		return items.get(position).getId();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		
		if(convertView==null)
		{
			LayoutInflater inf = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = inf.inflate(R.layout.item_producto, null);
		}
		
		ItmProducto itm = items.get(position);
		TextView txtItmProddesc= (TextView) v.findViewById(R.id.txtItmProddesc);
		txtItmProddesc.setText(itm.getDescripcion());
		TextView itmProdCod = (TextView) v.findViewById(R.id.itmProdCod);
		itmProdCod.setText(itm.getCodigo());
		TextView itmProdDesc2 = (TextView) v.findViewById(R.id.itmProdDesc2);
		itmProdDesc2.setText(itm.getDescripcion2());
		
		return v;
	}

}
